<template>
  <div class="app-container">
    <!-- <h1>仓库管理</h1> -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item
        label-width="40"
        :label="queryParams.auditType == '0' ? '供应商ID' : '承运商ID'"
        prop="orderId"
      >
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label-width="40"
        :label="queryParams.auditType == '0' ? '供应商名称' : '承运商名称'"
        prop="supplierName"
      >
        <el-input
          v-model="queryParams.supplierName"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label-width="100px" label="创建时间" prop="createTime">
        <QuickFilterDate
          :disableArr="[1, 2, 3, 4, 5, 6, 7]"
          v-model="queryDateArr"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['service/transport-distance:audit:export']"
          >导出</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="InventoryList"
      max-height="340"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="账单ID"
        width="100"
        :show-overflow-tooltip="true"
        align="center"
        prop="orderId"
      />
      <el-table-column
        label="账单生成时间"
        width="100"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="供应商ID"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="供应商名称"
        width="100"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="含抵顶支付"
        width="100"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="原料结算金额"
        width="100"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="运费结算金额"
        width="100"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />

      <el-table-column
        label="账单结算金额"
        width="100"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="已付款金额"
        width="100"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="对账状态"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="付款状态"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        label="附件状态"
        :show-overflow-tooltip="true"
        align="center"
        prop="contractId"
      />
      <el-table-column
        width="290px"
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleChangeMoney(scope.row)"
            v-hasPermi="['system:inventory:edit']"
            >修改结算金额</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleChangeList(scope.row)"
            v-hasPermi="['system:inventory:edit']"
            >账单修改记录</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:inventory:edit']"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAttachment(scope.row)"
            v-hasPermi="['system:inventory:edit']"
            >上传付款对账单</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleApplyPay(scope.row)"
            v-hasPermi="['system:inventory:edit']"
            >新增回款/修改回款</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <supplierAdd ref="supplierAdd"></supplierAdd>
    <carrier-add ref="carrierAdd"></carrier-add>
    <!-- 修改结算金额 -->
    <change-money ref="changeMoney"></change-money>
    <!-- 账单修改记录 -->
    <change-list ref="changeList"></change-list>
    <!-- 上传对账账单 -->
    <attachment ref="attachment"></attachment>
    <!-- 申请支付 -->
    <apply-pay ref="applyPay"></apply-pay>
  </div>
</template>
  
  <script>
import {
  listOrders,
  addInventory,
  updateInventory,
} from "@/api/service/orderCenter/purchase";
import NumberFormItem from "@/components/NumberFormItem";
import { listOnInfo } from "@/api/service/info";
import QuickFilterDate from "@/components/QuickFilterDate";
import supplierAdd from "./components/supplier-add.vue";
import carrierAdd from "./components/carrier-add.vue";
import applyPay from "./components/apply-pay.vue";
import attachment from "./components/attachment.vue";
import changeMoney from "./components/change-money.vue";
import changeList from "./components/change-list.vue";
export default {
  components: {
    NumberFormItem,
    QuickFilterDate,
    supplierAdd,
    carrierAdd,
    applyPay,
    attachment,
    changeMoney,
    changeList,
  },
  name: "inventory",
  data() {
    return {
      // 重置密码是否展示
      resetPassword: {
        visible: false,
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品--主标号表格数据
      InventoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        supplierName: null,
        rawMaterialName: null,
      },
    };
  },
  created() {
    this.getList();
  },
  computed: {
    queryDateArr: {
      get() {
        if (this.queryParams?.startTime) {
          return [this.queryParams?.startTime, this.queryParams?.endTime];
        }
        return [];
      },
      set(value) {
        this.queryParams.startTime = value[0];
        this.queryParams.endTime = value[1];
      },
    },
  },
  methods: {
    /** 查询产品--主标号列表 */
    getList() {
      this.loading = true;
      listOrders(this.queryParams).then((response) => {
        console.log(response);
        this.InventoryList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "service/transport-distance/audit/export",
        {
          ...this.queryParams,
        },
        `audit_${new Date().getTime()}.xlsx`
      );
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 新增按钮操作 */
    handleAdd() {},
    /* 重置密码*/
    handleChange(row) {
      this.$refs.change.handelInit(row);
    },
    // 修改结算金额
    handleChangeMoney(row) {
      this.$refs.changeMoney.handelInit(row);
    },
    // 账单修改记录
    handleChangeList(row) {
      this.$refs.changeList.handelInit(row);
    },
    // 上传附件-账单修改记录
    handleAttachment(row) {
      this.$refs.attachment.handelInit(row);
    },
    /** 详情 */
    handleDetail(row) {
      if (this.queryParams.auditType == "0") {
        this.$refs.supplierAdd.handelInit(row);
      } else {
        this.$refs.carrierAdd.handelInit(row);
      }
    },
    /** 申请付款 */
    handleApplyPay(row) {
      this.$refs.applyPay.handelInit(row);
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.edit-form {
  // display: flex;
  .form-label {
    font-size: 14px;
    font-weight: bold;
    line-height: 36px;
    padding-right: 30px;
    .form-red {
      color: #d23c26;
    }
  }
  .form-value {
    display: flex;
    //gap: 30px;
  }
}

::v-deep .el-tabs__content {
  max-height: 500px;
  overflow: auto;
}

.row-item {
  display: flex;
  // gap: 20px;
}
::v-deep .el-form-item__label {
  // width: 240px;
  text-align: right;
}
.form-right ::v-deep .el-input {
  width: 200px;
}
</style>